home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 7.3 KB | 239 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTextS.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWTXTSHP_H
- #define FWTXTSHP_H
-
- #ifndef FWSHAPE_H
- #include "FWShape.h"
- #endif
-
- #ifndef FWDFAULT_H
- #include "FWDfault.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTEDIT__)
- #include <TextEdit.h>
- #endif
-
- //==============================================================================
- // •• Forward Declarations
- //==============================================================================
-
- class FW_CGraphicContext;
- class FW_CTextShapeRep;
- class FW_CRectShape;
- class FW_COvalShape;
- class FW_CRoundRectShape;
- class FW_CArcShape;
- class FW_CLineShape;
- class FW_CRegionShape;
-
- //========================================================================================
- // •• Defines
- //========================================================================================
-
- enum FW_TextAlignment {
- FW_kAscentLine,
- FW_kBaseLine,
- FW_kDescentLine
- };
-
- //========================================================================================
- // •• CLASS FW_CTextShape
- //========================================================================================
-
- class FW_CTextShape : public FW_CShape
- {
- //----------------------------------------------------------------------------------------
- // • Constructors
- //
- public:
- FW_CTextShape();
- FW_CTextShape(long byteCount, const char* text,
- const FW_CPoint& position = FW_kZeroPoint,
- FW_TextAlignment textAlignment = FW_kBaseLine);
- FW_CTextShape(const FW_CString& string,
- const FW_CPoint& position = FW_kZeroPoint,
- FW_TextAlignment textAlignment = FW_kBaseLine);
-
- FW_CTextShape(const FW_CTextShape& other);
- FW_CTextShape(FW_CTextShapeRep* rep);
-
-
- //----------------------------------------------------------------------------------------
- // • Operators
- //
- public:
- FW_CTextShape& operator=(const FW_CTextShape& other);
- FW_CTextShape& operator=(FW_CTextShapeRep* other);
-
- FW_CTextShapeRep* operator->() const
- {return (FW_CTextShapeRep*)GetRep();}
-
- //----------------------------------------------------------------------------------------
- // • Conversion
- //
- public:
- operator FW_CRectShape() const;
- operator FW_COvalShape() const;
- operator FW_CRoundRectShape() const;
- operator FW_CArcShape() const;
- operator FW_CLineShape() const;
- operator FW_CRegionShape() const;
-
- //----------------------------------------------------------------------------------------
- // • Static Methods
- //
- public:
- static void DrawText(FW_CGraphicContext* graphicContext,
- long byteCount,
- const char* text,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment = FW_kBaseLine);
- static void DrawString(FW_CGraphicContext* graphicContext,
- const FW_CString& string,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment = FW_kBaseLine);
- };
-
- //==============================================================================
- // •• class FW_CTextShapeRep
- //==============================================================================
-
- class FW_CTextShapeRep : public FW_CShapeRep
- {
- friend class FW_CTextShape;
-
- //------------------------------------------------------------------------------
- // • Constructors/Destructors
- //
- protected:
- FW_CTextShapeRep();
- FW_CTextShapeRep(long byteCount, const char* text,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment);
- FW_CTextShapeRep(const FW_CString& string,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment);
-
- virtual ~FW_CTextShapeRep();
-
- //------------------------------------------------------------------------------
- // • Inherited API
- //
- public:
- // ----- Hit Testing -----
- virtual FW_HitTestPart HitTest(const FW_CPoint& test) const;
-
- // ----- Rendering -----
- virtual void Draw(FW_CGraphicContext* graphicContext);
- virtual void Draw(FW_CGraphicContext* graphicContext,
- const FW_CRect& box,
- FW_Justification justification = FW_kFlushDefault);
-
- static void DrawText(FW_CGraphicContext* graphicContext,
- long byteCount,
- const char* text,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment);
- static void DrawString(FW_CGraphicContext * graphicContext,
- const FW_CString& string,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment);
-
- // ----- Transform -----
- virtual void Transform(XMPTransform* transform);
- virtual void InverseTransform(XMPTransform* transform);
-
- virtual void MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY);
- virtual void MoveShapeTo(XMPCoordinate x, XMPCoordinate y);
-
- // ----- Geometry -----
- virtual FW_CRect GetShapeBounds() const;
-
- // ----- Default shape -----
- virtual void SetAsDefault() const;
-
- // ----- Stream -----
- virtual void Flatten(FW_CWritableStream& stream);
- virtual void Unflatten(FW_CReadableStream& stream);
-
- //------------------------------------------------------------------------------
- // • New API
- //
- public:
- FW_CTextShape Copy() const;
-
- long GetByteCount() const
- {return fByteCount;}
-
- FW_CPoint GetPosition() const
- {return fPosition;}
- FW_TextAlignment GetTextAlignment() const
- {return fTextAlignment;}
- long GetText(char* text) const;
-
- void SetPosition(const FW_CPoint& position)
- {fPosition = position; Changed();}
- void SetText(long byteCount, const char* text);
- void SetTextAlignment(FW_TextAlignment textAlignment)
- {fTextAlignment = textAlignment; Changed();}
-
- #ifdef FW_BUILD_MAC
- void GetMacTextStyle(TextStyle& theTextStyle) const;
- #endif
-
- private:
- static FW_SPlatformPoint CalcTextPosition(FW_CGraphicContext* graphicContext,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment);
-
- //------------------------------------------------------------------------------
- // • Data Members
- //
- protected:
- long fByteCount;
- char* fText;
- FW_CPoint fPosition;
- FW_TextAlignment fTextAlignment;
- };
-
- //==============================================================================
- // •• Inlines
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CTextShape::DrawText
- //------------------------------------------------------------------------------
- inline static void FW_CTextShape::DrawText(FW_CGraphicContext* graphicContext,
- long byteCount,
- const char* text,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment)
- {
- FW_CTextShapeRep::DrawText(graphicContext, byteCount, text, position, textAlignment);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CTextShape::DrawString
- //------------------------------------------------------------------------------
- inline static void FW_CTextShape::DrawString(FW_CGraphicContext* graphicContext,
- const FW_CString& string,
- const FW_CPoint& position,
- FW_TextAlignment textAlignment)
- {
- FW_CTextShapeRep::DrawString(graphicContext, string, position, textAlignment);
- }
-
- #endif